package com.ylyq.ylxx.model.bean;

import com.ylyq.ylxx.model.request.CreateCreativeRequest;
import com.ylyq.ylxx.model.request.GeneratePlansRequest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @ClassName ResultPlan
 * @Description TODO 里面属性的顺序不能随便更换，关联到使用它的构造方法
 * @Author xiaweichao
 * @Date 2020/7/22 16:11
 * @Version 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value="生成计划的属性内容")
public class ResultPlan {

    @ApiModelProperty(value = "组名称")
    private String groupName;
    @ApiModelProperty(value = "计划名称")
    private String planName;
    @ApiModelProperty(value = "落得页链接")
    private String external_url;

    @ApiModelProperty(value = "投放范围")
    private String delivery_range;
    @ApiModelProperty(value = "过滤已转化用户")
    private String hide_if_converted;
    @ApiModelProperty(value = "兴趣")
    private String inteset;
    @ApiModelProperty(value = "年龄")
    private String age;
    @ApiModelProperty(value = "地域")
    private AreaBean[] area;
    @ApiModelProperty(value = "性别")
    private String sex;
    @ApiModelProperty(value = "出价")
    private Double chujia;
    @ApiModelProperty(value = "日预算")
    private Double rys;
    @ApiModelProperty(value = "预估单个卖出成本")
    private Float sellCost;
    @ApiModelProperty(value = "预估卖出人数")
    private Long peopleSum;


    @ApiModelProperty(value = "商品名称")
    private String productName;
    @ApiModelProperty(value = "转化目标id")
    private Long covertId;
    @ApiModelProperty(value = "投放总预算")
    private Double budget;
    @ApiModelProperty(value = "公司名称")
    private String companyName;
    @ApiModelProperty(value = "广告头像")
    private String companyHead;
    @ApiModelProperty(value = "单个表单信息价值")
    private Double priceForm;

    @ApiModelProperty(value = "商品外形url，多个url用“,”拼接")
    private String chooseUrl;
    @ApiModelProperty(value = "商品条形码url，多个url用“,”拼接")
    private String chooseCodeUrl;
    @ApiModelProperty(value = "生成计划的属性内容-创意指定数据")
    private CreativeBean creativeBean;
    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    @ApiModel(value = "生成计划的属性内容-创意指定数据")
    public static class CreativeBean {
        @ApiModelProperty(value = "创意分类-三级行业")
        private Long cyfl;
        @ApiModelProperty(value = "广告位置")
        private Integer ggwz;
        @ApiModelProperty(value = "创意方式")
        private String cyfs;
        @ApiModelProperty(value = "品牌主页")
        private String ppzy;
        @ApiModelProperty(value = "自动生成视频素材。允许值：0（不启用），1（启用），默认：不启用")
        private Integer zdscspsc;
        @ApiModelProperty(value = "是否开启自动派生创意，大通投时可填，默认值: 1\n" +
                "允许值: 0(不启用), 1(启用)")
        private Integer creative_auto_generate_switch;

        @ApiModelProperty(value = "最优创意衍生计划。允许值：0（不启用），1（启用），默认：不启用")
        private Integer zycyysjh;
        @ApiModelProperty(value = "\t是否关闭评论，0为开启，1为关闭，默认值：0；\n" +
                "允许值: 0, 1")
        private Integer ggpl;
        @ApiModelProperty(value = "\t创意展现方式\n")
        private String cyzx;
        @ApiModelProperty(value = "创意标签")
        private List<String> cybq;
        @ApiModelProperty(value = "创意来源")
        private String ly;
        @ApiModelProperty(value = "创意标题")
        private List<CreateCreativeRequest.TitleListBean> cybt;
//        private List<CreativeTitle> cybt;
        @ApiModelProperty(value = "行动号召")
        private String xdhz;
        @ApiModelProperty(value = "创意投放位置,详见【附录-投放位置】，请注意广告位中的头图信息流（INVENTORY_FEED）与头条详情页（INVENTORY_TEXT_LINK）已合并为头条系（依然使用INVENTORY_FEED字段，名称更改为头条系）")
        private String[] inventory_type;
        @ApiModelProperty(value = "创意数据")
//        private List<GeneratePlansRequest.CreativeListBean> image_list;
        private List<CreateCreativeRequest.ImageListBean> image_list;

    }
    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    @ApiModel(value = "生成计划的属性内容-创意标题")
    public static class CreativeTitle {
        @ApiModelProperty(value = "创意标题，")
        private String title;
        @ApiModelProperty(value = "动态词包ID")
        private String[] creative_word_ids;
    }
    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    @ApiModel(value = "生成计划的属性内容-地域数据")
    public static class AreaBean {
        @ApiModelProperty(value = "城市ID")
        private Long cityID;
        @ApiModelProperty(value = "城市名")
        private String cityName;


        @Override
        public boolean equals(Object obj) {
            if(this == obj){
                return true;//地址相等
            }

            if(obj == null){
                return false;//非空性：对于任意非空引用x，x.equals(null)应该返回false。
            }

            if(obj instanceof AreaBean){
                AreaBean other = (AreaBean) obj;
                //需要比较的字段相等，则这两个对象相等
                if(equalsStr(this.cityName, other.cityName)
                        && this.cityID==other.cityID){
                    return true;
                }
            }

            return false;
        }

        private boolean equalsStr(String str1, String str2){
            if(StringUtils.isEmpty(str1) && StringUtils.isEmpty(str2)){
                return true;
            }
            if(!StringUtils.isEmpty(str1) && str1.equals(str2)){
                return true;
            }
            return false;
        }

        @Override
        public int hashCode() {
            int result = 17;
            result = 31 * result + (cityID == null ? 0 : cityID.hashCode());
            result = 31 * result + (cityName == null ? 0 : cityName.hashCode());
            return result;
        }
    }

}
